<template>
    <el-dialog :title="config.title" :visible.sync="visible" :width="config.width">
        <div>
            <SimpleTable v-if="config.components =='table'" :config="config.content" :value="data" />
            <FormBase v-if="config.components == 'form'" :config="config.content" :value="data" />
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button v-for="item,index in config.action" :key="index" @click="handlerAction(item)" :type="item.type" :icon="item.icon" size="small">{{item.label}}</el-button>
        </span>
    </el-dialog>
</template>
<script type="text/javascript">
import FormBase from '@/components/FormBase'
import SimpleTable from '@/components/SimpleTable'
//通过命名空间的方式映入
import { createNamespacedHelpers } from 'vuex'
//获取需要管理的方法
const { mapState, mapActions, mapMutations } = createNamespacedHelpers('multifunction')
export default {
    name: "tablealert",
    props: {
        value: Boolean,
        config: [Object, Array],
        data: [String, Number, Object, Array]
    },
    components: {
        FormBase,
        SimpleTable
    },
    data() {
        return {
            // 自动生成表格组件中表格的唯一码
            fieldKey: 0,
        }
    },
    computed: {
        visible: {
            get() {
                return this.value;
            },
            set(val, old) {
                this.$emit('input', val);
            }
        }
    },
    mounted() {

    },
    methods: {
        ...mapMutations(['retData']),
        ...mapMutations(['setURL']),
        ...mapActions(['submitFormData']),

        /**
         * 弹窗按钮
         * @return {[type]} [description]
         */
        handlerAction(item) {
            console.log(item);
            if (item.callback && item.callback.type == 'submit') {
                //	设置提交接口
                this.setURL({ model: item.callback.url[0], action: item.callback.url[1] });
                // 回调数据
                var _this = this;
                this.retData(function(res) {
                    _this.submitFormData();
                })
                console.log('数据交互');
            };
            this.visible = false;
        }
    }
}
</script>
<style type="text/css" lang="scss">
</style>